import { Constructor } from "cc";
import { inject } from "../inject";
import { Actor } from "./Actor";
import { Command } from "./Command";
import { CommandMap } from "./impl/CommandMap";
import { MediatorMap } from "./impl/MediatorMap";
import { ViewMap } from "./impl/ViewMap";

export abstract class Facade extends Actor {
    @inject('core.MediatorMap')
    public mediatorMap: MediatorMap;

    @inject('core.ViewMap')
    public viewMap: ViewMap;

    @inject('core.CommandMap')
    public commandMap: CommandMap;

    init() {
        this.mapMediator();
        this.mapCommands();
    }

    public abstract mapMediator();
    public abstract mapCommands();

    protected mapCommand(event: string, commandClazz?: string | Constructor<Command>, oneshot?: boolean) {
        if (this.commandMap) {
            this.commandMap.mapCommand(event, commandClazz, oneshot);
        }
    }
    protected mapView(viewName: string, mediatorName: string, path: string) {
        if (this.viewMap) {
            this.viewMap.mapViewRes(viewName, path);
        }

        if (this.mediatorMap) {
            this.mediatorMap.mapView(viewName, mediatorName);
        }
    }
}